local huajin = fk.CreateSkill {
  name = "th_huajin",
  max_turn_use_time = 1,
}

huajin:addEffect(fk.TargetConfirming, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(huajin.name) and data.from ~= nil and data.from ~= player and data.from:isAlive() and
    target:isAlive() and data.from ~= target and data:isOnlyTarget(target) and
    target:compareDistance(player, 1, "<=") and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local name = data.card.name
    local _, dat = room:askToUseActiveSkill(player, {
      skill_name = "#th_huajin_sel",
      prompt = "#th_huajin-invoke::"..target.id..":"..name,
      extra_data = {
        skillName = huajin.name
      }
    })
    if dat then
      event:setCostData(self, dat)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    room:throwCard(dat.cards, huajin.name, player, player)
    data:cancelTarget(target)
    local cDraw = "#th_huajin-draw:"..player.id
    local cSlash = "#th_huajin-slash::"
    local choice
    local slash = Fk:cloneCard("slash")
    if not player.dead and data.from and not data.from.dead and
    not (player:isProhibited(data.from, slash) or player:prohibitUse(slash)) then
      cSlash = cSlash..data.from.id
      choice = room:askToChoice(target, {
        choices = {cDraw, cSlash},
        skill_name = huajin.name
      })
    else
      choice = cDraw
    end
    if choice == cSlash then
      room:useVirtualCard("slash", nil, player, data.from, huajin.name)
    elseif choice == cDraw then
      player:drawCards(1, huajin.name)
      target:drawCards(1, huajin.name)
    end
  end,
}, { check_skill_limit = true })

Fk:loadTranslationTable{
  ["th_huajin"] = "化劲",
  [":th_huajin"] = "每回合限一次，与你距离不大于1的角色成为另一名其他角色使用牌的唯一目标时，你可以弃置两张同颜色牌取消之，然后你令目标选择一项：1.你与其摸一张牌；2.你视为对使用者使用一张【杀】。",

  ["#th_huajin-invoke"] = "化劲：你可以弃置两张同颜色牌，取消对 %dest 使用的 %arg",
  ["#th_huajin-draw"] = "%src与你摸一张牌",
  ["#th_huajin-slash"] = "视为对%dest使用一张杀",
}

return huajin